package action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import pageModel.Json;
import pageModel.User;
import pageModel.Vip;
import service.VipServiceI;

import com.opensymphony.xwork2.ModelDriven;

@Namespace("/")
@Action(value="vipAction")
public class VipAction extends BaseAction implements ModelDriven<Vip>{
Vip vip =new Vip();
private VipServiceI vipService;
	@Override
	public Vip getModel() {
		// TODO Auto-generated method stub
		return vip;
	}
	public VipServiceI getVipService() {
		return vipService;
	}
	@Autowired
	public void setVipService(VipServiceI vipService) {
		this.vipService = vipService;
	}
	public void datagrid(){
		super.writeJson(vipService.datagrid(vip));
	}
	public void add(){
		Json j=new Json();
		try{
			vipService.save(vip);
			j.setSuccess(true);
			j.setMsg("添加成功!");
		}catch(Exception e){
			j.setMsg("添加失败,该卡号在数据库中已存在!");
		}
		super.writeJson(j);
	}
	public void del(){
		Json j=new Json();
		try{
		vipService.remove(vip.getIds());
		j.setSuccess(true);
		j.setMsg("删除成功!");
	  }catch(Exception e){
		j.setMsg("删除失败!"); 
	  }
		super.writeJson(j);
	}
	public void editor(){
		Json j=new Json();
		try{
		vipService.edit(vip);
		j.setSuccess(true);
		j.setMsg("编辑成功!");
	  }catch(Exception e){
		j.setMsg("编辑失败!"); 
	  }
		super.writeJson(j);
	}
}
